package com.mumu.muPictureBackend.model.enums;

import lombok.Getter;

import java.util.HashMap;
import java.util.Map;

/**
 * 图片状态枚举类
 */
@Getter
public enum PictureRoleEnum {
    //定义两个枚举: 枚举之前用逗号分隔
    REVIEWING("待审核", 0),
    PASS("通过", 1),
    REJECT("拒绝", 2);

    private final String text;
    private final Integer value;

    PictureRoleEnum(String text, Integer value) {
        this.text = text;
        this.value = value;
    }


    //加载该类的时候就将所有枚举放到map中 然后查找枚举就可以实现用O(1)的时间复杂度 每次哦
    static final Map<String, PictureRoleEnum> getEnumByTest = new HashMap<>();
    static final Map<Integer, PictureRoleEnum> getEnumByValue = new HashMap<>();

    static {
        for (PictureRoleEnum userRoleEnum : PictureRoleEnum.values()) {
            getEnumByTest.put(userRoleEnum.getText(), userRoleEnum);
        }

        for (PictureRoleEnum userRoleEnum : PictureRoleEnum.values()) {
            getEnumByValue.put(userRoleEnum.getValue(), userRoleEnum);
        }
    }

    //根据枚举值获取枚举
    public static PictureRoleEnum getEnumByTest(String value) {
        return getEnumByTest.get(value);
    }

    public static PictureRoleEnum getEnumByValue(Integer value) {
        return getEnumByValue.get(value);
    }


}
